<template>
  <a-modal
    title="编辑模板"
    :width="640"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
      >
        <a-form-model-item label="模板内容" ref="text" prop="text">
            <a-textarea  v-model="form.text" size='large' style="height:300px"/>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { editText } from "@/services/textTemplate/textTemplate";
export default {
  name: "TenantForm",
  data() {
    return {
      labelCol: { span: 7 },
      wrapperCol: { span: 10 },
      visible: false,
      confirmLoading: false,
      form: {
          text:`<!DOCTYPE html>
                    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
                    <head>
                        <meta charset="utf-8" />
                    </head>
                    <body>
                        {{content}}
                    </body>
                    </html>`
      },
      displayName: '',
      rules: {
        text: [
          { required: true, message: "必须填写", trigger: "blur" },
        ],
      },
    };
  },
  created() {
  },
  methods: {
    handleSChange(e) {
      this.form.isEnabled  = e.target.checked;
    },
    handleChangeFei(value) {
        this.form.valueType = value
    },
    handleChange(e) {
      this.form.required  = e.target.checked;
    },
    openModal(model){
      this.visible = true;
      this.displayName = model.name
    //   this.form = model
    //   if(model && model.id){
    //     this.propId = model.id
    //   }
    },
    resetForm() {
      this.form = {};
    },
    handleCancel() {
      this.visible = false
      this.currentStep = 0
    },
    handleOk() {
      const form = this.$refs.ruleForm;
      this.confirmLoading = true;
      form.validate((valid) => {
        if (valid) {
          let values = {
              content: this.form.text,
              templateName: this.displayName
          }
          editText(values)
            .then((res) => {
              this.visible = false;
              form.resetFields();
              this.$message.info("操作成功");
              this.$emit('ok')
            })
            .finally(() => {
              this.confirmLoading = false;
            });
        } else {
          this.confirmLoading = false;
        }
      });
    }
  },
};
</script>

<style scoped>
</style>